package com.sf.fy.uav.applet.popscreen;

import com.sf.fy.uav.controller.PopUpScreenRest;
import com.sf.fy.uav.entity.PopUpScreen;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author ta136817
 */
@RequiredArgsConstructor
public class PopScreenScheduleTask extends QuartzJobBean {

    private final PopUpScreenRest popUpScreenRest;
    @Override
    protected void executeInternal(@NonNull JobExecutionContext context) {
        //开始时间超过或刚好等于了当前时间还未开始的 未开始弹屏记录
        List<PopUpScreen> noStartPopUpScreens = popUpScreenRest.getNoStartPopUpScreen();
        //结束时间已超过当前时间或刚等于当前时间还没有结束的 进行中弹屏记录
        List<PopUpScreen> inProgressPopUpScreens = popUpScreenRest.getInProgressPopUpScreen();
        List<String> noStartPopUpScreenIds = noStartPopUpScreens.stream().map(PopUpScreen::getId).toList();
        List<String> inProgressPopUpScreenIds = inProgressPopUpScreens.stream().map(PopUpScreen::getId).toList();
        if(!CollectionUtils.isEmpty(noStartPopUpScreenIds)){
            popUpScreenRest.updateStatusBatch(noStartPopUpScreenIds);
        }
        if(!CollectionUtils.isEmpty(inProgressPopUpScreenIds)){
            popUpScreenRest.updateInProgressStatus(inProgressPopUpScreenIds);
        }
    }
}
